package com.bobo.vote.service.impl;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;


import com.bobo.vote.dao.TopicMapper;
import com.bobo.vote.domain.Item;
import com.bobo.vote.domain.Topic;
import com.bobo.vote.service.TopicService;
import com.yudongyang.utils.NumberUtil;

@Service
public class TopicServiceImpl implements TopicService {
	@Resource
	private TopicMapper topicMapper;

	@Override
	public List<Topic> selects() {
		List<Topic> list = topicMapper.selects();//获取所有的投票主题
		for (Topic topic : list) {
			List<Item> items = topic.getItems();//获取投票项
			for (Item item : items) {
				//投票比例 =  用户投票数 /  投票总合计 
				//调用工具类 获取 投票比例
				  int percent = NumberUtil.getPercent(item.getVotes(), item.getTotal());
				item.setScale(new BigDecimal(percent));
			}
			
		}
		return list;
	}

}
